/*
 * Created on May 8, 2005
 *
 */
package org.mushroomdb.engine.operation.impl;

import java.util.Iterator;

import org.mushroomdb.catalog.Table;
import org.mushroomdb.engine.operation.AbstractUnaryRelationOperation;
import org.mushroomdb.engine.optimizer.RelationOperationVisitor;
import org.mushroomdb.executionplan.ExecutionPlanElement;
import org.mushroomdb.executionplan.ExecutionPlanElementImpl;


/**
 * @author Matias
 *
 */
public class ScanOperation extends AbstractUnaryRelationOperation {
	private Table table;

	/**
	 * @param relationOperation
	 */
	public ScanOperation(Table table) {
		super(null);
		this.table = table;
	}

	/**
	 * @see org.mushroomdb.engine.operation.RelationOperation#execute()
	 */
	public Iterator execute() {
		return this.table.getRegisters();
	}

	/**
	 * toString
	 */
	public String toString() {
		return "Scan(" + this.table.getName() + ")";  //$NON-NLS-1$//$NON-NLS-2$
	}

	/**
	 * @see org.mushroomdb.engine.operation.RelationOperation#buildExecutionPlan()
	 */
	public ExecutionPlanElement buildExecutionPlan() {
		ExecutionPlanElementImpl executionPlan = new ExecutionPlanElementImpl(this.toString()); //$NON-NLS-1$
		return executionPlan;
	}

	/**
	 * Agregado por Hache para optimizar
	 * @return
	 */
	public void accept(RelationOperationVisitor v) {
		v.visitScan(this);		
	}
	
	/**
	 * Agregado por Hache para optimizar
	 * @return
	 */
	public Table getTable() {
		return this.table;
	}
}
